<template>
	<div class="myOrder">

		<span @click="clickPrompt" class="userPrompt">
			{{ `您待确认定稿的订单数：${userData.confirm_total ? userData.confirm_total : 0 } ` }}
		</span>

		<el-popover placement="left" trigger="click">
			<template :loading="loading">
				<!-- 随便给个data就行，否则无法弹出 -->
				<el-checkbox v-model="checked" @change="allChange">全选</el-checkbox><br />
				<el-checkbox v-model="checked0">订单编号</el-checkbox><br />
				<el-checkbox v-model="checked6">订单状态</el-checkbox><br />
				<el-checkbox v-model="checked1">专利权人</el-checkbox><br />
				<el-checkbox v-model="checked2">发明人</el-checkbox><br />
				<el-checkbox v-model="checked3">专利名称</el-checkbox><br />
				<el-checkbox v-model="checked4">专利类型</el-checkbox><br />
				<el-checkbox v-model="checked5">代理人</el-checkbox><br />
				<el-checkbox v-model="checked8">提交时间</el-checkbox><br />
				<!-- <el-checkbox v-model="checked7">备注信息</el-checkbox><br /> -->
				<el-checkbox v-model="checked9">专属顾问</el-checkbox><br />
			</template>
			<el-button style="float: right;margin-bottom: 5px;margin-top: 0;" slot="reference" icon='el-icon-arrow-down'>显示字段</el-button>
		</el-popover>

		<!-- 列表查找 -->
		<span class="down-execel">
			<Poptip v-model="showFilter" @on-popper-show ='getAllAgent'  placement="bottom-end">
				<i class="el-icon-search poptip-condition-add"></i>
				<a href="javascript:;">列表查找</a>
				<div slot="content">
					<Poptip v-model="showFilterCondition" placement="bottom-start" class='poptip-condition'>
						<i class="el-icon-plus poptip-condition-add"></i>
						<a href="javascript:;" class='poptip-condition-add'>添加过滤条件</a>

						<div slot="content" class="condition-list">
							<ul>
								<li v-for="(item, index) in columns" :key="index" class = 'poptip-condition-item' @click="addFilterCondition(item)">{{item.label}}</li>
							</ul>
						</div>
					</Poptip>

					<el-form :model="conditionForm" ref="conditionForm" label-min-width="120px" class="demo-dynamic" @submit.native.prevent>
						<el-form-item
								v-for="(condition, index) in conditionForm.condition"
								:label="condition.label"
								:key="condition.key"
								:prop="'condition.' + index + '.value'"
								:rules="{ required: true, message: condition.label +'不能为空'}">

							<el-select v-if='condition.label === "订单状态"' v-model="condition.value" placeholder="请选择订单状态" size="small">
								<el-option label="待接单" value="待接单"></el-option>
								<el-option label="代理人撰写中" value="代理人撰写中"></el-option>
								<el-option label="案件内审中" value="案件内审中"></el-option>
								<el-option label="案件修改中" value="案件修改中"></el-option>
								<el-option label="定稿文件发送中" value="定稿文件发送中"></el-option>
								<el-option label="发明人确认定稿中" value="发明人确认定稿中"></el-option>
								<el-option label="上报文件上传中" value="上报文件上传中"></el-option>
								<el-option label="文件格式审核中" value="文件格式审核中"></el-option>
							</el-select>
							<el-select
								size="small"
								filterable
								v-model="condition.value"
								v-else-if='condition.label === "代理人"'>
								<el-option
									v-for="item in agentOptions"
									:key="item.id"
									:label="item | agentNumAddName"
									:value="item.id">
								</el-option>
							</el-select>
							<el-select
								size="small"
								filterable
								v-model="condition.value"
								v-else-if='condition.label === "专属顾问"'>
								<el-option
									v-for="item in processOptions"
									:key="item.id"
									:label="item.email_work.split('@')[0].split('followup')[1]"
									:value="item.id">
								</el-option>
							</el-select>

							<el-date-picker
								v-model="submitTime"
								type="daterange"
								placeholder="选择日期"
								value-format="yyyy-MM-dd"
								size="small"
								:validate-event='false'
								@input = 'changInput'
								v-else-if='condition.label === "提交时间"'>
							</el-date-picker>

							<el-select v-else-if='condition.label === "专利类型"' v-model="condition.value" placeholder="请选择专利类型" size="small">
								<el-option label="发明专利" value="发明专利"></el-option>
								<el-option label="实用新型" value="实用新型"></el-option>
								<el-option label="外观设计" value="外观设计"></el-option>
								<el-option label="不确定" value="不确定"></el-option>
							</el-select>

							<el-input v-else size="small" v-model="condition.value" @keyup.enter.native="submitsearch('conditionForm')"></el-input>
							<el-button @click.stop="removeDomain(condition)" size="mini">删除</el-button>
						</el-form-item>
					</el-form>

					<div class= 'btns'>
						<el-button @click="submitsearch('conditionForm')" size="mini">查询</el-button>
						<el-button  @click.stop="resetForm('conditionForm')" size="mini">重置</el-button>
					</div>
				</div>
			</Poptip>
		</span>

		<el-table
			v-if="table_show"
			ref="orderTb"
			filters
			id="orderTable"
			:data="tableData"
			border
			style="width: 100%;"
			height="87%"
			v-loading="loading"
			@sort-change='tableSortChange'
			@row-click='selectRow'>
			<!-- @row-click="rowClick" -->
			<el-table-column show-overflow-tooltip prop="id" label="ID" min-width="60" align="left" v-if='checked99'>
				<template slot-scope="scope">
					{{(scope.$index+1)+(currentPage-1)*tableSize}}
				</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip v-if="checked0" prop="order_number" label="订单编号" min-width="200" align="left" sortable='custom'>
			</el-table-column>
			<el-table-column show-overflow-tooltip v-if="checked6" prop="status" label="订单状态" min-width="130" align="left" sortable='custom'>
				<template slot-scope="scope">
					<div class="more" >
						<span v-if="scope.row.status == '发明人确认定稿中'" class="font_danger">{{scope.row.status}}</span>
						<span v-else>{{ scope.row.status }}</span>
					</div>
				</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip v-if="checked4" prop="type" label="专利类型" min-width="130" align="left" sortable='custom'>
				<template slot-scope="scope">
					<div class="more">{{scope.row.type}}</div>
				</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip v-if="checked3" prop="patent_name" label="专利名称" min-width="150" align="left" sortable='custom'>
				<template slot-scope="scope">
					<div class="more">{{scope.row.patent_name}}</div>
				</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip v-if="checked1" prop="patent_user" label="专利权人" min-width="130" align="left" sortable='custom'>
				<template slot-scope="scope">
					<div class="more">{{scope.row.patent_user}}</div>
				</template>
			</el-table-column>

			<el-table-column show-overflow-tooltip v-if="checked2" prop="user_name" label="发明人" min-width="130" align="left" sortable='custom'>
				<template slot-scope="scope">
					<div class="more">{{scope.row.user_name}}</div>
				</template>
			</el-table-column>
			<el-table-column v-if="checked9" prop="process_id" label="专属顾问" min-width="130" align="left" sortable='custom'>
				<template slot-scope="scope">
					<!-- <div class="more">{{scope.row.process.name}}</div> -->
					<div class="more">
						<span style="margin-right: 10px" v-if="scope.row.process && scope.row.process.email_work"> {{ scope.row.process.email_work.split("@")[0].split("followup")[1] }} </span>
						<Tooltip  v-if="scope.row.process"  content="点我留言">
							<i class="el-icon-chat-dot-round leaveWord" @click="leaveWord(scope.row)"></i>
						</Tooltip>
					</div>
				</template>
			</el-table-column>
			<el-table-column v-if="checked5" prop="agent_id" label="代理人" min-width="130" align="left" sortable='custom'>
				<template slot-scope="scope">
					<div class="more">
						<span v-if="scope.row.agent" >{{ scope.row.agent | agentNumber }}</span>
						<Tooltip  v-if="scope.row.agent"  content="点我留言">
							<i class="el-icon-chat-dot-round leaveWord" @click="leaveWordD(scope.row)"></i>
						</Tooltip>
					</div>
				</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip v-if="checked8" prop="created_at" label="提交时间" sortable min-width="180" align="left">
				<template slot-scope="scope">
					<!-- <i class="el-icon-time"></i> -->
					<!-- <span style="margin-left: 10px">{{ scope.row.created_at }}</span> -->
					<div class="more">{{scope.row.created_at}}</div>
				</template>
			</el-table-column>

			<el-table-column :fixed="isFixed" width="100" align="center" v-if="checked99">
				<!--  :fixed="isFixed"  -->
				<template slot="header">
					<span class="tableLastCol">操作</span>
				</template>

				<template slot-scope="scope">
					<el-button size="mini" type="danger"  @click.stop="reminders(scope.row.id, scope.row, scope.$index)"
					:disabled='!(scope.row.remind_count < 3 && getRemindTime(scope.row.remind_at, scope.row.created_at, scope.row.status)) || !(scope.row.status == "代理人撰写中" || scope.row.status == "待接单")'>催单</el-button>
					<!-- <el-button size="mini" type="danger" @click.stop="getRemindTime(scope.row.remind_at)">催单</el-button> -->
				</template>
			</el-table-column>
		</el-table>

		<el-pagination class="pagination" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
			:page-sizes="pageSizes" :page-size="Number(pageSize)" layout="total, sizes, prev, pager, next, jumper" :total="total">
		</el-pagination>

		<!-- 查看订单弹出框 -->
		<el-dialog  @open='openLook' :modal='false' center :visible.sync="$store.state.lookOrder" class='lookOrder' :destroy-on-close='true'  @close='closeLook'>
			<template slot="title">
				<div class='no-padding'>
					<span class="lookOrder-title">查看订单</span>
				</div>
			</template>
				<el-row :gutter="24">
				<el-col :span="12">
					<el-form :model="orderDetails" ref="lookorderDialog" label-min-width="120px" class='lookeOerderFrom'>
						<el-row type="flex">
							<el-col :span="12">
								<el-form-item label="专利名称：">{{ orderDetails.patent_name }}</el-form-item>
							</el-col>
							<el-col :span="12">
								<el-form-item label="专利类型：">{{ orderDetails.type }}</el-form-item>
							</el-col>
						</el-row>
						<el-row type="flex">
							<el-col :span="12">
								<el-form-item label="订单编号：">{{ orderDetails.order_number }}</el-form-item>
							</el-col>
							<el-col :span="12">
								<el-form-item label="状态："><span class="fontgreen">{{ orderDetails.status }}</span></el-form-item>
							</el-col>
						</el-row>
						<el-row type="flex">
							<el-col :span="12">
								<el-form-item label="代理人：">
									<span  class="fontgreen" v-if='orderDetails.agent' >{{ orderDetails.agent.email_work ? orderDetails.agent.email_work.split("@")[0].slice(-3) : '-' }}号</span>
									<span v-else ></span>
								</el-form-item>
							</el-col>
							<el-col :span="12">
								<el-form-item label="专属顾问：">
									<span  class="fontgreen" v-if='orderDetails.process'>{{ orderDetails.process.email_work.split("@")[0].split("followup")[1] + '号' }}</span>
									<span v-else ></span>
								</el-form-item>
							</el-col>
						</el-row>
						<el-row type="flex">
							<el-col :span="12">
								<el-form-item label="专利权人：">{{ orderDetails.patent_user }}</el-form-item>
							</el-col>
							<el-col :span="12">
								<el-form-item label="发明人：">{{ orderDetails.user_name }}</el-form-item>
							</el-col>
						</el-row>
						<el-row type="flex">
							<el-col :span="12">
								<el-form-item label="身份证号：">{{ orderDetails.id_card }}</el-form-item>
							</el-col>
							<el-col :span="12">
								<el-form-item label="联络人：">{{ orderDetails.liaisons }}</el-form-item>
							</el-col>
						</el-row>
						<el-row type="flex">
							<el-col :span="12">
								<el-form-item label="联络人邮箱：">{{ orderDetails.liaisons_email }}</el-form-item>
							</el-col>
							<el-col :span="12">
								<el-form-item label="联络人电话：">{{ orderDetails.liaisons_tel }}</el-form-item>
							</el-col>
						</el-row>
						<el-form-item class="mr0" label="技术领域：">{{ orderDetails.territory }}</el-form-item>
						<el-form-item class="mr0" label="技术背景：">{{ orderDetails.background }}</el-form-item>
						<el-form-item class="mr0" label="技术问题：">{{ orderDetails.problem }}</el-form-item>
						<el-form-item class="mr0" label="技术方案：">{{ orderDetails.plan }}</el-form-item>
						<el-form-item class="mr0" label="项目优势：">{{ orderDetails.advantage }}</el-form-item>
						<el-form-item class="mr0" label="具体实施方式：">{{ orderDetails.way }}</el-form-item>
						<el-row type="flex">
							<el-col :span="12" >
								<el-form-item label="附图：">
									<div v-if="orderDetails.img" class="file-box preview-img-wrap">
											<!-- <a class="el-icon-picture-outline file_sh" :href="baseUrl + '/api/download?path=' + '/' + orderDetails.img"
											:download="orderDetails.img" :title="orderDetails.img"></a> -->
										<el-image
											v-for="(item, index) in orderDetails.img_arr"
											:key="index"
											:src="item"
											:preview-src-list="orderDetails.img_arr"
										></el-image>
										<!-- <a v-for="item in orderDetails.imgArr" :key="item.id" :href="baseUrl + '/api/download?path='  + item.file +'/'+ item.path"
											:download="item.path" :title="item.path" class="el-icon-picture-outline file_sh"></a> -->
									</div>
									<!-- {{ orderDetails.img }} -->
								</el-form-item>
							</el-col>
							<el-col :span="12">
								<!-- <span>附件：</span>
								<span v-if='orderDetails.file'>{{ orderDetails.file }}</span>
								<span v-else>&nbsp;</span> -->
								<el-form-item label="附件：">
									<div class="file-box" v-if="orderDetails.file">
											<a v-for="item in orderDetails.fileArr" :key="item.id" :href="baseUrl + '/api/download?path='  + item.file +'/'+ item.path"
											:download="item.path" :title="item.path" class="el-icon-tickets file_sh"></a>
											<!-- <a class="el-icon-picture-outline file_sh" :href="baseUrl + '/api/download?path=' + '/' + orderDetails.file"
											:download="orderDetails.file" :title="orderDetails.file"></a> -->
									</div>
								</el-form-item>
							</el-col>
						</el-row>

						<el-form-item class="mr0 clearfloat" label="定稿文件：">
							<div class="file-box" v-if="orderDetails.fishArr">
								<a v-for="item in orderDetails.fishArr" :key="item.id" :href="baseUrl + '/api/download?path='  + item.file +'/'+ item.path"
								:download="item.path" :title="item.path" class="el-icon-tickets file_sh"></a>
								<!-- <a class="el-icon-picture-outline file_sh" :href="baseUrl + '/api/download?path=' + '/' + orderDetails.file"
								:download="orderDetails.file" :title="orderDetails.file"></a> -->
							</div>
							<div v-if="orderDetails.fishArr && orderDetails.status == '发明人确认定稿中'" class="file-btns">
								<!-- {{ orderDetails }} -->
								<el-button v-no-more-click:3000 size="mini" type="primary" @click="confirmFishFile('confirm', orderDetails.id,orderDetails)">确认定稿</el-button>
								<el-button v-no-more-click:3000 size="mini" type="danger" @click="confirmFishFile('back', orderDetails.id,orderDetails)">退回定稿</el-button>
							</div>
						</el-form-item>
						<el-row v-if="orderDetails.grades">
							<el-col :span="12">
								<el-form-item label="服务态度：" style="border-bottom-width: 1px;" class="flex-form">
									<el-rate
										disabled
										show-score
										allow-half
										v-model="orderDetails.grades.attitude">
									</el-rate>
								</el-form-item>
							</el-col>
							<el-col :span="12">
								<el-form-item label="撰写质量：" style="border-bottom-width: 1px;" class="flex-form">
									<el-rate
										disabled
										show-score
										allow-half
										v-model="orderDetails.grades.quelity">
									</el-rate>
								</el-form-item>
							</el-col>
						</el-row>
						<el-row v-if="orderDetails.grades">
							<el-col :span="24">
								<el-form-item label="撰写耗时" style="border-bottom-width: 1px;" class="flex-form">
									<el-rate
										disabled
										show-score
										allow-half
										v-model="orderDetails.grades.take_time">
									</el-rate>
								</el-form-item>
							</el-col>
						</el-row>
						<el-row v-if="orderDetails.grades">
							<el-col :span="24">
								<el-form-item label="评价：" style="border-bottom-width: 1px;">
								{{orderDetails.grades.remark}}
								</el-form-item>
							</el-col>
						</el-row>
						<el-row type="flex" justify="center" class="mt10" >

							<template v-if="orderDetails.status == '上报文件上传中'">
								<el-button v-if="orderDetails.is_grades == 0" type="success" size="small" @click="agentRate(orderDetails)" :disabled="orderDetails.is_grades != 0">
									案件评分
								</el-button>
								<template v-if="orderDetails.grades">
									<el-button v-if="orderDetails.grades.remark == '' " class="ml10" type="success" size="small" @click="additionalRate(orderDetails)">
										追加评论
									</el-button>
								</template>
								<el-button v-if="orderDetails.grades && orderDetails.grades.total_score / 3 > 4.5" type="primary" size="small" @click="reward(orderDetails)">
									打赏
								</el-button>
							</template>
							
							<!-- <el-button class="ml10" type="success" size="small" @click="additionalRate(orderDetails)">追加评论
									</el-button> -->
							<el-button
                v-if="orderDetails.is_distribution == 3 && orderDetails.order_number.slice(0, 2) == 'ZB'"
								:disabled="order_pay && order_pay.pay_status != 2"
                type="warning"
                size='small'
                @click.stop="goPay(orderDetails)">去支付
              </el-button>

						</el-row>
					</el-form>
				</el-col>
				<el-col :span="12" class="lookOrder-right ">
					<el-steps :active="opDateMax" class="steps" align-center finish-status="success" process-status='success'>
						<el-step v-for="(item,index) in stepsText" :title="item" description="" :key="index">
						</el-step>
					</el-steps>
					<br />
					<div class="lookOrder-right-collapse">
						<el-collapse accordion v-if="showOP">
							<el-collapse-item title="详细流程" name="1">
								<Timeline class="steps" style="padding: 10px 0 0 0;">
									<template v-for="(item, index) in opData">
										<Timeline-item color="blue" v-if="item.id==14" :key="index">
											{{item.pivot.created_at+'  '+'案件已撤案。'}}
										</Timeline-item>
										<Timeline-item color="blue" v-if="item.id==13" :key="index">
											{{item.pivot.created_at+'  '+'发明人确认定稿。'}}
										</Timeline-item>

										<Timeline-item color="blue" v-if="item.id==12" :key="index">
											<!-- {{item.pivot.created_at+'  '+'代理人变更为：'+order.agent.name}} -->
											{{item.pivot.created_at }} 代理人变更为： <span class="fontgreen" > {{ order.agent.email_work.split("@")[0].slice(-3) }}号</span>
										</Timeline-item>

										<Timeline-item color="blue" v-if="item.id==10" :key="index">
											{{ item.pivot.created_at }} 代理人：<span class="fontgreen" > {{ order.agent.email_work.split("@")[0].slice(-3) }}号 </span>，已发送定稿文件。
											<!-- {{item.pivot.created_at+'  '+'代理人：'+order.agent.name+'已发送定稿文件。'}} -->
										</Timeline-item>

										<Timeline-item color="blue" v-if="item.id==8" :key="index">
											{{item.pivot.created_at+'  '+'等待提交国知局。'}}
										</Timeline-item>

										<Timeline-item color="blue" v-if="item.id==7" :key="index">
											{{item.pivot.created_at+'  '+'案件定稿文件已上传。'}}
										</Timeline-item>

										<Timeline-item color="blue" v-if="item.id==5" :key="index">
											{{item.pivot.created_at+'  '+'案件质控中。'}}
										</Timeline-item>

										<Timeline-item color="blue" v-if="item.id==4" :key="index">
											{{item.pivot.created_at+'  '+'案件质控通过。'}}
										</Timeline-item>

										<Timeline-item color="blue" v-if="item.id==3" :key="index">
											{{item.pivot.created_at+'  '+'案件撰写完毕,质控中。'}}
										</Timeline-item>

										<Timeline-item color="blue" v-if="item.id==2" :key="index">
											<!-- {{item.pivot.created_at+'  '+'订单已分配代理人：'+ order.agent.name +',联系电话：'+order.agent.phone+'。案件撰写中。'}} -->
											{{ item.pivot.created_at }} 订单已分配代理人：<span class="fontgreen" >{{  order.agent.email_work.split("@")[0].slice(-3) }}号</span> 联系电话：{{ order.agent.phone }} 案件撰写中。
										</Timeline-item>

										<Timeline-item color="blue" v-if="item.id==1" :key="index">
											{{ item.pivot.created_at }} 提交成功,本次订单您的专属顾问是：<span class="fontgreen" >{{ order.process.email_work.split("@")[0].split("followup")[1]+'号' }}</span> {{ '联系电话：'+ order.process.phone + '。' }}
										</Timeline-item>
									</template>
								</Timeline>
								<!-- <el-steps :space="35" class="steps" direction="vertical" :active="opData.length" align-center>
									<el-step v-for="item in opData" :title="item.pivot.created_at+'  '+item.name" description="">
									</el-step>
								</el-steps> -->
							</el-collapse-item>
							<el-collapse-item title='退回定稿留言' name='2'>
								<el-timeline class= 'messageList' v-if="orderDetails.customer_opinions.length">
									<el-timeline-item
										v-for="(item, index) in orderDetails.customer_opinions"
										:key="index"
										:timestamp="item.created_at"
									>
										<el-card class="messagebox">
											<Tooltip content="点我回复" class="fr" >
												<i class="el-icon-chat-dot-round leaveWord ml5" @click="showTextarea(item, index)"></i>
											</Tooltip>
											<div class="item">
												<span class="item_time">{{item.created_at}}</span>
												<span class="item_user">发明人</span>
												<div class="item_message messageBackground_l">
													<span>{{item.review_cn}}</span>
												</div>
											</div>
											<div v-for="(agent, index2) in item.agent_message" :key="index2">
												<div class="agent_item clearfloat" v-if="agent.role_id == '2'">
													<span class="item_user fr">代理人</span>
													<span class="item_time fr">{{agent.created_at}}</span>
													<div class="item_message messageBackground_r fr">
														<span>{{agent.review_cn}}</span>
													</div>
												</div>
												<div v-else class="item">
													<span class="item_time">{{agent.created_at}}</span>
													<span class="item_user">发明人</span>
													<div class="item_message messageBackground_l">
														<span>{{agent.review_cn}}</span>
													</div>
												</div>
											</div>
											<div v-if="item.show_input" class="clearfloat mt20">
												<el-input type="textarea" :rows="4" placeholder="请输入内容" v-model="replyMessage"></el-input>
												<el-button class="fr mt10" type="primary" @click="submit(item)">发送</el-button>
												<!-- <el-button class="fr mt10 mr10" @click="resets ">重置</el-button> -->
											</div>
										</el-card>
									</el-timeline-item>
								</el-timeline>
								<p v-else class="tc">
									暂无数据
								</p>
							</el-collapse-item>
						</el-collapse>
					</div>
				</el-col>
			</el-row>

		</el-dialog>

		<!-- 留言框 -->
		<el-dialog title="留言" :visible.sync="showRefund4" center @close='leaveWordClose' class="leaveWordDialog">
			<span class='leaveWord-label'>请输入你的留言</span>
			<el-input type="textarea" v-model="leaveWordText"></el-input>
			<span slot="footer" class="dialog-footer">
				<el-button v-no-more-click:3000 type="warning" size="small" @click="cancel">取消</el-button>
				<el-button v-no-more-click:3000 @click='submitLeaveWord' type="primary" size="small" :loading="isLeaveWord">确定</el-button>
			</span>
		</el-dialog>

		<!-- 信息提示框 -->
		<promptMessage ref='promptMessage' @getData ='search1' @agentRate="agentRate"/>

		<!-- 评分 -->
		<rate ref="rate" @refresh="refresh"></rate>

		<!-- 追加评分 -->
		<additionalRate ref="additionalRate" @refresh="refresh" :type='2'></additionalRate>

		<!-- 打赏 -->
		<reward ref='reward' @refresh="refresh"></reward>

		</div>
</template>

<script>
import { timeout } from 'q';
import promptMessage from '~/components/promptMessage'
import rate from '~/components/rate'
import additionalRate from '~/components/additionalRate'
import fncSearch from '~/components/searchSrceen/fnc-search.js'
import moment from 'moment'
import { getMyInfo } from "~/api/user"
import {sendPrivateLetter} from '~/util/index'
import reward from '../components/reward'

	export default {
		data() {
			return {
				table_show: true,
				checked: true,
				checked0: true,
				checked1: true,
				checked2: true,
				checked3: true,
				checked4: true,
				checked5: true,
				checked6: true,
				checked7: true,
				checked8: true,
				checked9: true,
				checked99: true,
				loading: true,
				tableData: [],
				pageSizes: [25, 50],
				pageSize: 25,
				tableSize: 10, //一页几条
				tableStart: 0, //table数组过滤的第一条索引
				tableEnd: 10, //table数组过滤的最后一条索引
				currentPage: 1, //目前在第几页
				showOP: false,
				opData: [],
				opDateMax: 1, //状态里最大的id是多少
				stepsText: ['提交申请', '代理人接单', '案件撰写', '案件质控', '发送定稿文件', '发明人定稿', '案件上传', '递交国知局'],
				routeid: 'orderInProcess',
				orderNumber: '',

				showRefund4: false,
				refundID: '',
				refundIndex: '',
				isFixed: 'right',
				order_number: '',
				lastTime: 0,
				total: 0,
				order:{},
				orderDetails: {},
				leaveWordText: '',
				leaveWordId: '',
				//附图图片
				imgArr: [],
				//附件文件
				fileArr: [],
				// 定稿文件
				fishArr: [],
				baseUrl: global.baseurl,
				showFilter: false, // 控制显示筛选条件
				showFilterCondition: false,
				conditionForm: {
					condition: []
				}, //筛选条件
				columns: [
					{
						label: '订单编号',
						id: 3,
						parameter: 'order_number',
					},
					{
						label: '订单状态',
						id: 1,
						parameter: 'status'
					},
					{
						label: '专利类型',
						id: 10,
						parameter: 'type'
					},
					{
						label: '专利名称',
						id: 2,
						parameter: 'patent_name'
					},
					{
						label: '专利权人',
						id: 12,
						parameter: 'patent_user'
					},
					{
						label: '发明人',
						id: 13,
						parameter: 'user_name'
					},
					{
						label: '专属顾问',
						id: 5,
						parameter: 'process_id'
					},
					{
						label: '代理人',
						id: 9,
						parameter: 'agent_id'
					},
					{
						label: '提交时间',
						id: 15,
						parameter: 'subimt_time'
					}
				],
				searchValue: '',
				submitTime: [],
				agentOptions: [],
				processOptions: [],
        LorD: '',
        tableSelectRow: {},
				leaveWordEmail: '',
				leaveWordData: {},
				paramsByOrder: {
					status: '待接单,代理人撰写中,案件内审中,案件修改中,定稿文件发送中,发明人确认定稿中,上报文件上传中,文件格式审核中'
				},
				sortQuery: {

				},
				userData: {},
				isLeaveWord: false,
				replyMessage: '',
				privateLetterId: null,
			}
		},
		created() {
			this.getData()
			this.getUserData()
			this.getMyinfo()
		},
		computed :{
			selectArr() {
				let arr = [this.checked0, this.checked1, this.checked2, this.checked3, this.checked4, this.checked5, this.checked6, this.checked8, this.checked9]
				return arr
			}
		},
		components: {
			promptMessage,
			fncSearch,
			rate,
			reward,
			additionalRate
		},
		methods: {
			goPay(data) {
				this.$router.replace({
					name: 'payment',
					query: {
						// finals_id: data.id,
						order: data.order.id,
						from: this.$route.path
					}
				})
			},
			additionalRate (data) {
				// this.$store.commit('setLookOrder', false)
				let order = {
					id: data.id,
					grades: data.grades
				}
				this.$alert('该评价信息为匿名评价，代理人不可见', '提示', {
					confirmButtonText: '确定',
					callback: action => {
						this.$refs['additionalRate'].show(order)
					}
				})
			},
			reward(data) {
				this.$refs['reward'].show(data)
			},
			async getMyinfo (params) {
				let myInfo = await getMyInfo(this.$axios, params);
				if (myInfo.data.status == 'success') {
					this.$store.commit("setRoleInfo",myInfo.data.data)
					this.$store.commit("setUser",myInfo.data.data)
					this.myInfo = myInfo.data.data
					this.roleID = this.myInfo.role_id
				}
			},
			refresh() {
				this.$store.commit('setLookOrder', false)
				this.search1()
			},
			agentRate(data) {
				console.log(data)
				this.$refs['rate'].showOn(data)
			},
			gwm() {
				//水印,非管理员要设置
				if (this.$store.state.user.role_id != 1
					&& this.$route.path != '/admin/register'
					&& this.$route.path != '/admin/personalCenter/dstribution'
					&& this.$route.path != '/admin/personalCenter/myPurse'
					&& this.$route.path != '/admin/activityList/activityConfig'
					&& this.$route.path != '/admin/activityList/sysConfig'
					&& this.$route.path !='/admin/login'
					&& this.$route.path != '/admin/agentImprove'
					&& this.$route.path != '/order/login') {
					let that = this;
					let gwm = require('gwm');
					gwm.creation({
						'txt': that.$store.state.user.name,
						'container': '.el-table', //#gwm
						'fontSize': 40
					})
				}
			},
			allChange(val) {
				if (val) {
					this.checked0 = true;
					this.checked1 = true;
					this.checked2 = true;
					this.checked3 = true;
					this.checked4 = true;
					this.checked5 = true;
					this.checked6 = true;
					this.checked7 = true;
					this.checked8 = true;
					this.checked9 = true;
				} else {
					this.checked0 = false;
					this.checked1 = false;
					this.checked2 = false;
					this.checked3 = false;
					this.checked4 = false;
					this.checked5 = false;
					this.checked8 = false;
					this.checked7 = false;
					this.checked6 = false;
					this.checked9 = false;
				}
			},
			// 获取用户信息
			getUserData () {
				this.$axios.get('/api/consumer/show')
				.then( res => {
					if (res.data.code == '200') {
						this.userData = res.data.data
					}
				})

			},
			getData(pPage) {
				let that = this;
				//我的订单列表
				that.$axios.get('/api/consumer/order', {
					params: {
						status: '待接单,代理人撰写中,案件内审中,案件修改中,定稿文件发送中,发明人确认定稿中,上报文件上传中,文件格式审核中',
						page: pPage,
						sort_str: 'created_at',
						sort_order: 'desc'
					}
				})
					.then(res => {
						that.loading = false;
						that.tableData = res.data.data;
						that.pageSize = res.data.page.per_page;
						that.tableSize = res.data.page.per_page;
						that.tableEnd = res.data.page.per_page;
						that.total = res.data.page.total;

						// 重绘表格解决错位问题
						this.$nextTick(()=>{
							this.$refs.orderTb.doLayout()
						})
					})
			},



			//选择一页几条
			handleSizeChange(size) {
				this.paramsByOrder.perPage = size
				this.paramsByOrder.page = 1
				this.$axios.get('/api/consumer/order',{
					params: this.paramsByOrder
					}
				)
				.then(res => {
					this.tableData = res.data.data;
					this.pageSize = res.data.page.per_page;
					this.tableSize = res.data.page.per_page;
					this.tableEnd = res.data.page.per_page;
					this.total = res.data.page.total;
				})
			},
			// 图片， 文件 分组
			imgs (data) {
				if (data.img == null || data.img == "") {} else {
					let img_Arr = data.img.split("&");
					data.imgArr = [];
					data.img_arr = []
					for (const i in img_Arr) {
						let itemobj = {
							id: i + 1,
							path: img_Arr[i],
							file: ''
						};
						let img = this.baseUrl + '/storage/upload/' + img_Arr[i]
						data.img_arr.push(img)
						let itemArr = itemobj.path.split("/")
						itemobj.path = itemArr[itemArr.length - 1]
						itemobj.file = itemArr.slice(0, 2).join("/");
						data.imgArr.push(itemobj);
					}
      			}
				//文件 切分组件
				if (data.file == null || data.file == "") {} else {
					let file_Arr = data.file.split("&");
					data.fileArr = [];
					for (const i in file_Arr) {
						let itemobj = {
							id: i + 1,
							path: file_Arr[i],
							file: ''
						};
						let itemArr = itemobj.path.split("/")
						itemobj.path = itemArr[itemArr.length - 1]
						itemobj.file = itemArr.slice(0, 2).join("/");
						data.fileArr.push(itemobj);
					}
				}

				if (data.confirm_file == null || data.confirm_file == "") {} else {
					let fish_Arr = data.confirm_file.split("&");
					data.fishArr = [];
					for (const i in fish_Arr) {
						let itemobj = {
							id: i + 1,
							path: fish_Arr[i],
							file: ''
						};
						let itemArr = itemobj.path.split("/")
						itemobj.path = itemArr[itemArr.length - 1]
						itemobj.file = itemArr.slice(0, 2).join("/");
						data.fishArr.push(itemobj);
					}
				}
				if (data.review_file == null || data.review_file == "") {} else {
					let fish_Arr = data.review_file.split("&");
					data.reviewFile = [];
					for (const i in fish_Arr) {
						let itemobj = {
							id: i + 1,
							path: fish_Arr[i],
							file: ''
						};
						let itemArr = itemobj.path.split("/")
						itemobj.path = itemArr[itemArr.length - 1]
						itemobj.file = itemArr.slice(0, 2).join("/");
						data.reviewFile.push(itemobj);
					}
				}
			},
			//获取所有代理人
			getAllAgent() {
				this.$axios.get('api/user/agent/all')
				.then(res => {
					if (res.data.code == 200) {
						this.agentOptions = res.data.data
					}
				})
				.catch(err => {
					this.$message({
						type: "err",
						message: err
					});
				})

				this.$axios.get('api/user/process')
					.then(res => {
						if (res.data.code == 200) {
							this.processOptions = res.data.data
						}
					})
					.catch(err => {
						this.$message({
							type: "err",
							message: err
						})
					})
			},

			handleCurrentChange(val) {
				// this.currentPage = val;
				this.paramsByOrder.page = val
				let that = this;
				let params = this.paramsByOrder

				// let page = val;
				that.$axios.get('/api/consumer/order?page=' + val,{
					params
				})
				.then(res => {
					that.loading = false;
					that.tableData = res.data.data;
					this.pageSize = res.data.page.per_page;
					this.tableSize = res.data.page.per_page;
					this.tableEnd = res.data.page.per_page;
					this.total = res.data.page.total;
				})
			},
			selectRow (row, column, event) {
				this.tableSelectRow = row
				if(window.getSelection().toString() === ''){
					this.orderDetails = row
					if (this.orderDetails.grades) {
						this.orderDetails.grades.attitude = Number(this.orderDetails.grades.attitude)
						this.orderDetails.grades.take_time = Number(this.orderDetails.grades.take_time)
						this.orderDetails.grades.quelity = Number(this.orderDetails.grades.quelity)
					}
					this.imgs(this.orderDetails)
					this.order = row
					let opData = [];
					opData.push(...row.statuss)

					let firstInternalAudit = null
					let lastInternalAudit = null
					let lastForYes = null
					let lastForNo = null
					var firstDate = ''
					// 拿第一次审计
					for (let i = 0; i < opData.length; i++) {
						if (opData[i].id == 3) {
							firstInternalAudit = opData[i]
							firstDate = new Date(firstInternalAudit.pivot.created_at.replace(/-/g, '/')).getTime()
						}
					}

					// 拿最后一次是审核通过或者是不通过
					for (let i = 0; i < opData.length; i++) {
						if (opData[i].id == 4) {
							lastForYes = opData[i]
							break
						}
					}
					for (let i = 0; i < opData.length; i++) {
						if (opData[i].id == 5) {
							lastForNo = opData[i]
							break
						}
					}
					let lastForYesTime = 0
					if (lastForYes) {
						lastForYesTime = new Date(lastForYes.pivot.created_at.replace(/-/g, '/')).getTime()
					}
					let lastForNoTime = 0
					if (lastForNo) {
						lastForNoTime	= new Date(lastForNo.pivot.created_at.replace(/-/g, '/')).getTime()
					}
					// 去除除第一次审核和最后一次审核外的其他审核流程
					let spliceArrays = []

					for (let i = 0; i < opData.length; i++) {
						if(firstInternalAudit) {
							if(opData[i].id == 3) {
								let itemTime = new Date(opData[i].pivot.created_at.replace(/-/g, '/')).getTime()
								if (firstDate != itemTime) {
									spliceArrays.push(i)
								}
							}
						}
					}

					for (let i = 0; i < opData.length; i++) {

						if(firstInternalAudit) {
							if(opData[i].id == 3) {
								let itemTime = new Date(opData[i].pivot.created_at.replace(/-/g, '/')).getTime()
							if (firstDate != itemTime) {
										spliceArrays.push(i)
									}
							}
						}

						if(lastForYes) {
							let lastForYesDate = lastForYes.pivot.created_at
							if(opData[i].id == 4) {
								if ((lastForYesDate == opData[i].pivot.created_at) && (lastForYesTime > lastForNoTime)) {
									continue
								} else {
									opData.splice(i, 1)
								}
							}
						}

						if(lastForNo) {
							let lastForNoDate = lastForNo.pivot.created_at
							if(opData[i].id == 5) {
								if ((lastForNoDate == opData[i].pivot.created_at) && (lastForNoTime > lastForYesTime)) {
									continue
								} else {
									opData.splice(i, 1)
								}
							}
						}
					}

					for (let i = 0; i < spliceArrays.length; i++) {
						opData.splice(spliceArrays[i], 1)
					}
					this.opData = [];
					this.opData.push(...opData);
					let opData2Temp = []

					for(let i in row.statuss){
						let obj = {
							id:row.statuss[i].id,
							name:row.statuss[i].name,
							created_at:row.statuss[i].created_at
						}
						let pivot = {}
						for(let m in row.statuss[i].pivot){
							pivot[m] = row.statuss[i].pivot[m]
						}
						obj.pivot = pivot;
						opData2Temp.push(obj);
					}

					//②opData数组按每个元素的“id”属性升序
					let opData2 = []
					opData2.push(...opData2Temp)
					opData2.reverse()


					let opDateMax = opData2.length - 1
					for (let i = opDateMax; i >= 0; i--) {
						if (opData2[i].id == 8) {
							this.opDateMax = 8;
							break;
						} else if (opData2[i].id == 7) {
							this.opDateMax = 7;
							break;
						} else if (opData2[i].id == 13) {
							this.opDateMax = 6;
							break;
						} else if (opData2[i].id == 10) {
							this.opDateMax = 5;
							break;
						} else if (opData2[i].id == 4) {
							this.opDateMax = 4;
							break;
						} else if (opData2[i].id == 3) {
							this.opDateMax = 3;
							break;
						} else if (opData2[i].id == 2) {
							this.opDateMax = 2;
							break;
						} else if (opData2[i].id == 1) {
							this.opDateMax = 1;
							break;
						}
					}
					this.showOP = true;
					// this.showRefund3 = true;
					this.$store.commit('setLookOrder', true)
				}
			},
			leaveWord (row) {
				this.showRefund4 = true;
				// this.showRefund3 = false;
				this.$store.commit('setLookOrder', false)
				this.leaveWordId = row.id
        this.LorD = '专属顾问'
				this.leaveWordEmail = row.process.email_work
				this.leaveWordData = row
				this.privateLetterId = row.process.id
			},
			leaveWordD (row) {
				this.showRefund4 = true;
				// this.showRefund3 = false;
				this.$store.commit('setLookOrder', false)
				this.leaveWordData = row
				this.leaveWordId = row.agent_id
				this.privateLetterId = row.agent_id
			},
			openLook(row) {
				if (this.showRefund4) {
					this.$store.commit('setLookOrder', false)
				}
      },
			closeLook () {
				// this.tableSelectRow = {}
			},
      submitLeaveWord () {
				let that = this
				// this.leaveWordEmail = row.agent.email_work
        let submitLeaveWordOrder = {
          message: that.leaveWordText,
          id: this.leaveWordId
        }
				let url = ''
				let agentName = ' '
				let isProcess = true
				if(this.leaveWordData.agent) {
					agentName= this.leaveWordData.agent.name
				}
        if(this.LorD === '专属顾问') {
					url = `api/consumer/${that.leaveWordId}/process/message`

        } else {
					url = `api/consumer/${that.leaveWordData.id}/message`
					isProcess = false
				}
				this.isLeaveWord = true

				sendPrivateLetter(this, this.leaveWordData.id, this.leaveWordText, this.privateLetterId, 'order')

        that.$axios.post(url, submitLeaveWordOrder)
        .then(({ data }) => {
          if (data.code == 200) {
						setTimeout(() => {
							this.showRefund4 = false;
						}, 500)
						this.isLeaveWord = false
						if(isProcess) {
							let pData = {
								userName: this.$store.state.user.name,
								email: this.leaveWordData.process.email_work,
								phone: this.leaveWordData.process.phone,
								number: this.leaveWordData.process.email_work.split("@")[0].split("followup")[1]
							}
							this.$refs['promptMessage'].showDialog('processLeaveWord',pData)
						} else {
							let pData = {
								userName: this.$store.state.user.name,
								email: this.leaveWordData.agent.email_work,
								phone: this.leaveWordData.agent.phone,
								number: this.leaveWordData.agent.email_work.split("@")[0].slice(-3)
							}
							this.$refs['promptMessage'].showDialog('agentLeaveWord',pData)
						}

          } else {
						this.isLeaveWord = false
            this.$message.error(data.message);
          }
        })
        this.LorD = ''
      },
			leaveWordClose () {
				this.leaveWordText = ''
				this.submitLeaveWordOrder = null
			},
			addFilterCondition (item) {
				let filterItem = {
					value: '',
					label: item.label,
					parameter: item.parameter,
					key: Date.now()
				}
				if (this.conditionForm.condition.length > 0) {
					let conditionlabels = []
					for(let i = 0; i < this.conditionForm.condition.length; i++) {
						conditionlabels.push(this.conditionForm.condition[i].label)
					}
					let Check = conditionlabels.indexOf(item.label)
					Check == -1 ? this.conditionForm.condition.push(filterItem) : this.$message.error('请勿重复添加')
				} else {
					this.conditionForm.condition.push(filterItem)
				}

				this.showFilterCondition = false;
			},
			search1() {
				this.currentPage = 1
				for(var i = 0; i < this.conditionForm.condition.length; i++) {
					let a = this.conditionForm.condition[i].parameter
					this.paramsByOrder[a] = this.conditionForm.condition[i].value

					if (this.conditionForm.condition[i].parameter === 'subimt_time') {
						this.paramsByOrder.start_time = this.submitTime[0]
						this.paramsByOrder.end_time = this.submitTime[1]
					}
				}
				// 处理分页数据
				delete this.paramsByOrder.page

				// 处理排序状态
				delete this.paramsByOrder.sort_str
				delete this.paramsByOrder.sort_order
				this.$refs['orderTb'].clearSort()
				if (!this.paramsByOrder.status) {
					this.paramsByOrder.status = '待接单,代理人撰写中,案件内审中,案件修改中,定稿文件发送中,发明人确认定稿中,上报文件上传中'
				}
				let that = this;
				//我的订单列表
				that.$axios.get('/api/consumer/order', {
					params: this.paramsByOrder
				})
				.then(res => {
					that.loading = false;
					that.tableData = res.data.data;
					this.pageSize = res.data.page.per_page;
					this.tableSize = res.data.page.per_page;
					this.tableEnd = res.data.page.per_page;
					this.total = res.data.page.total;
					this.showFilter = false
				})


				// this.tableData = data.tableData
				// this.total = this.tableData.length
			},
			resetForm(formName) {
				// this.$refs.addnew.$refs.conditionForma.resetFields()
				this.$refs['orderTb'].clearSort()
				// this.conditionForm.condition = []
				this.conditionForm.condition.forEach(v => {
					if (v.value) {
						v.value = null
					}
				});
				this.paramsByOrder = {
					status: '待接单,代理人撰写中,案件内审中,案件修改中,定稿文件发送中,发明人确认定稿中,上报文件上传中,文件格式审核中'
				}
				this.showFilterCondition = false
				this.submitTime = []
				this.$nextTick(() => {
					this.$refs[formName].clearValidate()
				})
				// this.showFilterCondition = false
				// this.getData()
				// this.showFilter = false
      },
			submitsearch(formName) {
				let that = this
				this.$refs[formName].validate((valid, prop) => {
				// this.$refs[formName].clearValidate();
					let props = []
					for (let k in prop) {
						props.push(prop[k][0].field)

						if (prop[k][0].message = '提交时间不能为空') {
							if (that.submitTime) {
								if (that.submitTime.length > 0) {
									that.$refs[formName].clearValidate([prop[k][0].field])
									// that.search()
									let timeIndex = props.indexOf('提交时间不能为空')
									props.splice(timeIndex, 1)
								}
							} else {
								return false
							}
						}
					}
					if (props.length) {
						that.$refs[formName].validateField(props, (valid2) => {
							if(valid2) {
								return false;
							} else {
								that.search1()
							}

						})
					} else {
						that.search1()
					}
				})
			},
			removeDomain(item) {
				this.showFilter = true
				delete this.paramsByOrder[item.parameter]
				let index = this.conditionForm.condition.indexOf(item)
				if (index !== -1) {
					this.conditionForm.condition[index] = []
					this.conditionForm.condition.splice(index, 1)
				}

				if (item.label === '提交时间') {
					this.submitTime = []
					delete this.paramsByOrder.start_time
					delete this.paramsByOrder.end_time
				}
				this.search1()
      },
      reminders (id, row) {
				let that = this
				let email,agentName  = ''
				let isProcess = true
				if(row.agent) {
					agentName= row.agent.name
				}
				if (row.status === '待接单') {
					email = row.process.email_work
				} else {
					email = row.agent.email_work
					isProcess = false
				}
        this.$axios.get(`api/consumer/order/${id}/remind`)
        .then (res => {
          if(res.data.code == 200) {
						if (isProcess) {
							let pData = {
								email: email,
								phone: row.process.phone,
								number: email.split("@")[0].split("followup")[1],
								userName: this.$store.state.user.name
							}
							this.$refs['promptMessage'].showDialog('processUrging',pData)
						} else {
							let pData = {
								email: email,
								phone: row.agent.phone,
								number: email.split("@")[0].slice(-3),
								userName: this.$store.state.user.name
							}
							this.$refs['promptMessage'].showDialog('agentUrging',pData)
						}
						that.search1()
            // that.getData(this.currentPage)
          } else {
            this.$message.error(res.data.message)
          }
        })
      },
      getRemindTime(pTime,pCreatedTime,status) {
				// scope.row.remind_at, scope.row.created_at, scope.row.status
				let remindTime = pTime
				let createdTime = pCreatedTime

				let createdTimeM = new Date(createdTime).getTime()
				let nowTimeM = new Date().getTime()

				let missedOrderTime = Math.floor((nowTimeM - createdTimeM) / 1000 / 60 / 60)

				if (missedOrderTime < 72) {
					return false
				}
        if (remindTime) {
          remindTime,createdTime = remindTime.replace(/-/g, "/");
          let remindTimeM = new Date(remindTime).getTime()
          let createdTimeM = new Date(createdTimeM).getTime()
					let nowTimeM = new Date().getTime()
					// 每次催单间隔时间
					let hour = Math.floor((nowTimeM - remindTimeM) / 1000 / 60 / 60 )
          if (hour > 72) {
            return true
          } else{
            return false
          }
        } else {
          return true
        }

			},

			changInput () {
				this.$refs['conditionForm'].clearValidate();
			},

			cancel () {
				this.showRefund4 = false
			},
			// 表格排序
			tableSortChange(column) {
				if (column.order === 'descending') {
					this.paramsByOrder.sort_str = column.prop
					this.paramsByOrder.sort_order = 'desc'
				} else if (column.order === 'ascending'){
					this.paramsByOrder.sort_str = column.prop
					this.paramsByOrder.sort_order = 'asc'
				} else {
					delete this.paramsByOrder.sort_str
					delete this.paramsByOrder.sort_order
				}
				this.loading = true;
				this.$axios.get('/api/consumer/order', {
					params: this.paramsByOrder
				})
				.then(res => {
					this.loading = false;
					this.tableData = res.data.data;
					this.pageSize = res.data.page.per_page;
					this.tableSize = res.data.page.per_page;
					this.tableEnd = res.data.page.per_page;
					this.total = res.data.page.total;
				})
			},
			clickPrompt () {
				let that = this
				that.loading = true
				// this.paramsByOrder.status = '发明人确认定稿中'
				// this.paramsByOrder.page = 1
				this.paramsByOrder = {
					status: '发明人确认定稿中',
					page: 1
				}
				that.$axios.get('/api/consumer/order', {
					params: this.paramsByOrder
				})
				.then(res => {
					that.loading = false;
					that.tableData = res.data.data;
					that.pageSize = res.data.page.per_page;
					that.tableSize = res.data.page.per_page;
					that.tableEnd = res.data.page.per_page;
					that.total = res.data.page.total;
					that.showFilter = false
				})
			},
			confirmFishFile (val,id,pData) {
				if (val == 'confirm') {
					this.$axios.get(`api/order/${id}/web/confirm/file`)
					.then (res => {
						if(res.data.code == '200') {
							let showMessageData = {
								order_id: id,
								agentPhone:pData.agent.phone,
								processPhone: pData.process.phone,
								agentNumber: pData.agent.email_work.split("@")[0].slice(-3),
								processNumber: pData.process.email_work.split("@")[0].split("followup")[1],
							}
							this.$refs['promptMessage'].showDialog('confirmFishFile',showMessageData)
							this.getUserData()
						}
					})
				} else {
					this.$prompt('请输入修改意见', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          inputPattern: /^[\s\S]*.*[^\s][\s\S]*$/,
          inputErrorMessage: '修改意见不能为空'
        }).then(({ value }) => {
					let data = {
						id: id,
						modification: value
					}
						this.$axios.get(`api/order/${id}/web/confirm/file`, {
							params: data
						})
						.then( res => {
							if(res.data.code == '200') {
								let showMessageData = {
									agentPhone:pData.agent.phone,
									processPhone: pData.process.phone,
									agentNumber: pData.agent.email_work.split("@")[0].slice(-3),
									processNumber: pData.process.email_work.split("@")[0].split("followup")[1],
								}
								this.$refs['promptMessage'].showDialog('confirmFishFileForNo',showMessageData)
								this.getUserData()
							}
						})
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '取消退回'
          })
        })
				}
			},

			submit(item) {
				if (this.replyMessage == "") {
					this.$message({
						message: "请输入消息",
						type: "warning"
					});
				} else {
					this.submitPost(item)
				}
			},
			showTextarea(item, index) {
				for(let i = 0; i < this.orderDetails.customer_opinions.length; i++) {
					this.orderDetails.customer_opinions[i].show_input = false;
					if (i == index) {
						this.orderDetails.customer_opinions[i].show_input = true
					}
				}
			},
			submitPost(data) {
				let params = {
					opinion_id: data.id,
					review: this.replyMessage,
					type: 'inventor'
				}
				this.$axios
					.post(`/api/order/${data.order_id}/agent_message`, params)
					.then(res => {
						if (res.data.code == 200) {
							this.$message({
								type: "success",
								message: "回复成功！"
							});
							this.replyMessage = ''
							this.getData(this.currentPage)
							setTimeout(() => {
								this.$store.commit('setLookOrder', false)
							}, 300)
						} else {
							this.$message({
								type: "error",
								message: res.data.message
							});
						}
					})
					.catch(e => {
						console.log(e);
					});
			},
		},
		updated() {
			let noP = document.getElementsByClassName('no-padding');
			for (let i = 0; i < noP.length; i++) {
				if (noP[i].parentNode && noP[i].parentNode.parentNode) {
					noP[i].parentNode.parentNode.style.padding = 0;
				}
			}
		},
		//配合.el-table{width:99.9%!important;}防止筛选抖动
		beforeUpdate() {
			// this.$nextTick(() => {
			// 	this.$refs.orderTb.doLayout();
			// });
		},
		beforeRouteEnter (to, from, next) {

			next(vm => {
				// 通过 `vm` 访问组件实例
				if (vm.$store.state.user.first == 1) {
					let isFirst = window.localStorage.getItem('first')
					if (!isFirst) {
						let text = ''
						vm.$store.state.user.name ? text = vm.$store.state.user.name : text = '用户'
						vm.$confirm(`尊敬的${text}，欢迎您使用信和红谷知识产权服务系统！您的初始密码为您手机号后6位，为了您的账号安全请您及时修改`, '温馨提示！', {
							confirmButtonText: '立即修改',
							cancelButtonText: '不修改',
							type: 'warning'
						}).then(() => {
							vm.$router.push({
								path: '/user/set/updatePwd'
							})
							window.localStorage.setItem('first', 2)
						}).catch(() => {
							vm.$alert(`尊敬的<span style="color: rgb(73, 150, 124)">${text}</span>，后续如需修改密码请前往<span style="color: rgb(73, 150, 124)"><a class='a' href='/user/set/updatePwd'> 个人中心 </a></span>进行操作。`, {
									confirmButtonText: '已知晓',
									dangerouslyUseHTMLString: true,
									callback: () => {
										window.localStorage.setItem('first', 2)
									}
								}
							)
						})
					}
				}
			})
		},
		watch: {
			selectArr(val) {
				this.table_show = false
				this.$nextTick(() => {
					this.table_show = true
				})
				setTimeout(() => {
					this.$nextTick(() => {
						this.gwm()
					})
				}, 300)
				if (val.some(v => v == false)) {
					this.checked = false
				} else {
					this.checked = true
				}
				if (val.every(v => v == false)) {
					this.checked99 = false
				} else {
					this.checked99 = true
				}
			},

    },
	}
</script>

<style lang="less" >
.flex-form {
  .el-form-item__content {
    height: 30px;
    display: flex;
    align-items: center;
  }
}
	.myOrder {
		.clearfix:after{
			content:"";
			height:0;
			display:block;
			clear:both;
		}
		.clearfix{
				zoom:1;
		}
		.el-step__head{
			&.is-wait{
				.el-step__icon {
					&.is-text{
						.el-step__icon-inner{
							display: none; //不要序号
						}
					}
				}
			}
		}
		.ivu-timeline-item-content{
			font-size: 15px!important;//字体放大点
			top: -9px;
		}
		.ivu-timeline-item-tail{
			border-left: 2px dashed #e8eaec;
		}
		.ivu-timeline-item-head-blue{
			margin-left: 3px;
			width: 8px;
			height: 8px;
			background: #2d8cf0;
		}
		.el-range-separator {
			width: 60px;
		}

		.card {
			margin: 20px 0;
			clear: both;
		}
		.lookOrder {
			overflow-y: scroll;
			.lookOrder-left {
				float: left;
				width: 50%;

			}
			.lookOrder-right {
				padding: 28px 0 0 20px !important;
				box-sizing: border-box;
				.lookOrder-right-collapse {
					padding-left: 20px;
					// max-height: 270px;
					// overflow-y: auto;
				}
			}
			.el-dialog{
				// min-width: 1500px ;
				width: 95%;
				// overflow-y: auto;
				// max-height: 100%;
				// overflow-x:;
        .el-dialog__body {
          padding: 20px;
        }
			}
			.textslineH{
				line-height: 25px !important;
			}

		}

		.search-input {
			width: 200px;
		}
		.leaveWordDialog {
			.el-dialog {
				width: 35%;
			}
			.leaveWord-label {
				display: block;
				margin-bottom: 10px;
			}
			.el-textarea {
				display: block;
				margin-bottom: 20px;
			}
		}
		.el-table {
			width: 99.9% !important;

			.el-table__header-wrapper{
				.has-gutter{
					.el-table__header{
						th:last-child {
							padding-right: 25px ;
						}
					}
				}

			}
		}

		height: 100%; //撑满表格
		.hr {
			border: 1px solid #c5cfdb;
		}

		.steps {
			margin-left: 20px;
		}

		.center-title {
			color: rgb(240, 173, 78);
			font-weight: bold;
		}

		.center-title2 {
			color: rgb(23, 140, 223);
			font-weight: bold;
		}

		.center-title3 {
			color: rgb(217, 83, 79);
			font-weight: bold;
		}

		.demo-ruleForm {
			margin-top: 20px;
		}

		.required-tag {
			color: #d9534f;
		}

		.submit-btn {
			margin-top: 50px;
		}

		.pagination {
			margin-top: 30px;
		}

		.tableTitle {
			position: relative;
			margin: 30px auto;
			// width: 600px;
			height: 1px;
			background-color: #d4d4d4;
			text-align: center;
			font-size: 16px;
			color: rgba(101, 101, 101, 1);
		}

		.midText {
			position: absolute;
			left: 50%;
			background-color: #ffffff;
			padding: 0 15px;
			transform: translateX(-50%) translateY(-50%);
		}



		.more {
			display: block;
			/* width: 31em; */
			word-break: keep-all;
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
		}

		.el-step__icon {
			width: 24px;
		}

		.applyBilling {
			.demo-ruleForm{
					.el-select {
						width: 100%;
					}
					.el-autocomplete{
						width: 100%;
					}
				}

		}
		.lookeOerderFrom {
			.el-form-item {
				height: 100%;
				padding-left: 10px;
				border: 1px solid #ccc;
				margin-right: -1px;
				margin-bottom: -1px;
				// border-bottom-width: 0;
				.el-form-item__label {
					line-height: 30px;
				}
				.el-form-item__content{
					line-height: 30px;
				}

			}
			.el-row {
				.el-col-12 {
					.el-form-item {
						border-bottom-width: 0;
					}
				}
			}
		}
		.file_sh {
			font-size: 20px;
			margin-right: 40px;
		}
		.leaveWord {
			color: rgb(16, 133, 16);
			font-size: 18px;
		}
		.steps {
			.el-step__main{
				// min-width: 110px;
				width: 100%;
				.el-step__title {
					text-align: center;
					font-size: 15px;
					width: 100%;
					line-height: 20px;
				}
			}
      .el-step:nth-child(odd) {
        .el-step__main{
          position: absolute;
          top: -40px;
        }
			}
			.el-step:nth-child(even) {
        .el-step__main{
          margin-top: 15px;
        }
			}
			.el-steps--vertical {
				width: 420px;
				margin: 0 auto;
			}
		}

	}

	.poptip-condition {
		display: block;
		margin-top: 10px;
		.poptip-condition-item {
			line-height: 25px;
			cursor:pointer;
		}
		.poptip-condition-add {
			font-size: 14px;
		}
	}
	.demo-dynamic {
		padding-left: 10px;
		.el-form-item {
			margin-bottom: 12px;
		}
		.el-input {
			width: 240px;
		}
		.el-date-editor {
			width: 240px;
		}
		.el-button {
			padding: 9px 15px;
			vertical-align: baseline;
		}
		.el-form-item__error {
			padding-top: 0 ;
		}
	}
	.el-main .ivu-poptip .ivu-poptip-popper .ivu-poptip-content .ivu-poptip-inner{
		min-width: 480px ;
		// height: 300px;
		overflow-y:scroll;
	}
	.el-main .poptip-condition .ivu-poptip-popper .ivu-poptip-content .ivu-poptip-inner {
		min-width: 180px;
	}
	.down-execel {
		display: block;
		height: 40px;
		line-height: 40px;
		color: #333333;
		font-size: 14px;
		margin-right: 20px;
		float: right;
	}
	.btns {
		margin-top: 10px;
	}
	.tableLastCol {
   	padding-right: 15px;
	}
	.fontgreen {
		color: rgb(73, 150, 124);
		font-weight: 700;
  }
  .lookOrder-title {
    font-size: 18px;
    margin-right: 30px;
    // font-weight: 700;
	}

	.userPrompt {
		display: inline-block;
		border-radius: 3px;
		cursor: pointer;
		padding: 11px 15px;
		color: #e6a23c;
    background: #fdf6ec;
    border-color: #f5dab1;
	}
	.file-btns {
		margin: 10px 0;
	}
	.file-box {
		-webkit-display:flex;
		height: 30px;
		display:flex;
		-webkit-align-items:center;
		align-items:center;
		-webkit-justify-content:left;
		justify-content:left;

		// height: 30px;
    // display: flex;
    // align-items: center;
    // justify-content: center;
	}
	.a {
		text-decoration: underline;
	}
	.preview-img-wrap {
		display: flex;
		align-items: center;
		.el-image {
			width: 20px;
			height: 20px;
			margin-right: 10px;
			image {
				width: 100%;
				height: 100%;
				display: block;
			}
		}
	}
	.messageList {
		.messagebox {
			width: 100%;
			background: #eef1f3;
		}

		.messageBackground_l {
			background: #fff;
		}
		.messageBackground_r {
			background: #c9e7ff;
		}
		.item {
			width: 100%;
			margin-bottom: 10px;
			.item_user {
				display: inline-block;
				width: 60px;
				font-size: 16px;
				font-weight: bold;
			}
			.item_message {
				max-width: calc(100% - 170px);
				display: inline-block;
				padding: 10px 15px;
				box-sizing: border-box;
				margin-left: 15px;
				border-radius: 5px;
				vertical-align: top;
				// margin-right: 90px;
			}
			.item_time {
				font-size: 12px;
				display: block;
				padding-left: 80px;
				margin-bottom: 5px;
				color: #ccc;
			}
			.deduction_message {
				margin: 20px 0 0 80px;
				max-width: calc(100% - 170px);
				padding: 10px 15px;
				border-radius: 5px;
			}
		}
		.agent_item {
			width: 100%;
			margin-bottom: 10px;
			position: relative;
			box-sizing: border-box;
			padding-top: 20px;
			.item_user {
				display: inline-block;
				width: 60px;
				font-size: 16px;
				font-weight: bold;
			}
			.item_time {
				position: absolute;
				right: 95px;
				top: 0px;
				font-size: 12px;
				display: block;
				// padding-right: 80px;
				margin-bottom: 5px;
				color: #ccc;
			}
			.item_message {
				max-width: calc(100% - 180px);
				display: inline-block;
				padding: 10px 15px;
				box-sizing: border-box;
				margin-right: 30px;
				border-radius: 5px;
				vertical-align: top;
				// margin-left: 80px;
			}
		}
	}
	.el-collapse {
		.el-collapse-item {
			.el-collapse-item__content {
				max-height: 400px;
				overflow-y: auto;
			}
		}
	}
</style>
